/*
 * @Author: fengweicong 75202172+fengweicong@users.noreply.github.com
 * @Date: 2022-07-21 15:12:37
 * @LastEditors: fengweicong 75202172+fengweicong@users.noreply.github.com
 * @LastEditTime: 2022-07-27 16:40:33
 * @FilePath: \大宗买卖\ebuy\src\router\index.js
 * @Description: 
 * 
 * Copyright (c) 2022 by fengweicong 75202172+fengweicong@users.noreply.github.com, All Rights Reserved. 
 */
/*
 * @Descripttion: 
 * @version: 
 * @Author: lyw
 * @Date: 2022-02-07 16:05:05
 * @LastEditors: fengweicong 75202172+fengweicong@users.noreply.github.com
 * @LastEditTime: 2022-07-27 15:37:11
 */
import Vue from 'vue'
import Router from 'vue-router'
import Login from './Login'
import Pay from './Pay'
import Main from './Main/index'
import store from '@/vuex'
import { isAccountLoginIn, isSalerLoginIn } from '@/utils/authority'

Vue.use(Router)

// 解决： 3.0以上点击同一路由报错
const VueRouterPush = Router.prototype.push
Router.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

const router = new Router({
  routes: [
    ...Main,
    ...Login,
    ...Pay,
  ]
})

router.beforeEach((to, from, next) => {
  
  // 账号登录拦截
  if (to.meta.requireAccountLoginIn && !isAccountLoginIn()) {
    next({ path: '/login/login' });
  }
  
  // 保存动态参数
  if (JSON.stringify(to.params) !== '{}') {
    store.state.params = {...to.params}
  }
  next()
});

export default router